package org.fatmansoft.teach.controllers;

import org.fatmansoft.teach.models.Teacher;
import org.fatmansoft.teach.payload.request.DataRequest;
import org.fatmansoft.teach.payload.response.DataResponse;
import org.fatmansoft.teach.payload.response.OptionItemList;
import org.fatmansoft.teach.service.StudentService;
import org.fatmansoft.teach.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;

import javax.validation.Valid;

@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/api/teacher")
public class TeacherController {

    @Autowired
    TeacherService teacherService;
    //获取teacher列表
    @PostMapping("/getTeacherList")
    public DataResponse getTeacherList(@Valid @RequestBody DataRequest dataRequest) {
        return teacherService.getTeacherList(dataRequest);
    }
    //添加/编辑教师
    @PostMapping("/teacherEditSave")
    public DataResponse addTeacher(@Valid @RequestBody DataRequest dataRequest) {
        return teacherService.teacherEditSave(dataRequest);
    }
    //删除教师
    @PostMapping("/teacherDelete")
    public DataResponse deleteTeacher(@Valid @RequestBody DataRequest dataRequest) {
        return teacherService.teacherDelete(dataRequest);
    }
    /**
     * saveTeacherIntroduce 前端学生个人简介信息introduce提交服务
     * @param dataRequest 从前端获取 teacherId teacher表 teacher_id introduce 学生个人简介信息
     * @return  操作正常
     */
    @PostMapping("/saveTeacherIntroduce")
    @PreAuthorize("hasRole('ROLE_TEACHER')")
    public DataResponse saveTeacherIntroduce(@Valid @RequestBody DataRequest dataRequest) {
        return teacherService.saveTeacherIntroduce(dataRequest);
    }
    /**
     * getTeacherIntroducePdf 生成获取个人简历的PDF数据流服务
     * @param dataRequest  teacherId 教师主键
     * @return  返回PDF文件二进制数据
     */
    @PostMapping("/getTeacherIntroducePdf")
    public ResponseEntity<StreamingResponseBody> getTeacherIntroducePdf(@Valid @RequestBody DataRequest dataRequest) {
        return teacherService.getTeacherIntroducePdf(dataRequest);
    }
    @PostMapping("/getTeacherIntroduceData")
    public DataResponse getTeacherIntroduceData(@Valid @RequestBody DataRequest dataRequest) {
        return teacherService.getTeacherIntroduceData(dataRequest);
    }
    /*
    @PostMapping("/getTeacherCourse")
    public DataResponse getTeacherCourse(@Valid@RequestBody DataRequest dataRequest) {
        return teacherService.getTeacherCourse(dataRequest);
    }*/
}
